package com.youlu.campus.service.qa;

import com.youlu.campus.entity.*;
import com.youlu.campus.entity.VO.req.QaCommitCommand;
import com.youlu.campus.entity.VO.req.QaInfoReq;
import com.youlu.campus.entity.VO.req.QaPracticeCommitCommand;
import com.youlu.campus.entity.VO.req.UserQaQueryVO;
import com.youlu.campus.entity.VO.res.*;
import com.youlu.campus.entity.english.UserCompetitionQa;
import com.youlu.campus.entity.english.vo.request.QueryQaHomeCommand;
import com.youlu.campus.entity.english.vo.response.UserQaScoreResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface UserQaInfoService {

    void create(UserQaInfo req);

    boolean update(UserQaInfo req);

    List<UserQaInfo> list(UserQaInfo req);

    boolean updateByQaNo(String userId, String activityId, Integer qaNo, Double score);

    QQUserQaRes findByActivityId(UserPO currentUser, String activityId);

    UserQaScoreResponse doQaCommit(QaCommitCommand qaCommitCommand);

    /**
     * 校验答题次数限制
     *
     * @param qaUserId
     * @param qaInfoId
     */
    void checkQaLimit(Integer type, String qaUserId, String qaInfoId);

    /**
     * 根据用户ID查询用户参与活动答题邀请统计
     *
     * @param userId
     * @return
     */
    List<UserQaInviteInfoRes> queryUserQaInviteStatisticsByUserId(String userId);

    /**
     * 获取用户答题请
     *
     * @param currentUser
     * @param activityId
     * @param contestQaType 1、非专业竞赛 2、专业组竞赛
     * @return
     */
    ActivityPlusUserQaRes findUserQaInfoByUserIdAndActivityId(UserPO currentUser, Integer contestQaType, String activityId);

    /**
     * 获取用户答题分数及证书
     *
     * @param queryQaHomeCommand
     * @return
     */
    UserCompetitionQa findByUserIdAndScore(QueryQaHomeCommand queryQaHomeCommand);

    /**
     * 查询用户练习答题接口返回结果
     *
     * @param currentUser
     * @param activityId
     * @return
     */
    H5UserQaPracticeRes findUserQaQaPracticeByUserId(UserPO currentUser, String activityId, String qaInfoId);


    /**
     * 用户练习答题提交
     *
     * @param qaPracticeCommitCommand
     * @return
     */
    UserQaPracticeResult doQaPracticeCommit(QaPracticeCommitCommand qaPracticeCommitCommand);

    /**
     * 习题清空-重置
     *
     * @param qaInfoReq
     */
    void qaPracticeReset(QaInfoReq qaInfoReq);

    /**
     * 获取用户错误题库练习题库列表
     *
     * @param h5QaPracticeErrorQuery
     * @return
     */
    Page<ActivityQuestionInfo> findUserQaPracticeErrorList(H5QaPracticeErrorQuery h5QaPracticeErrorQuery);

    /**
     * 获取用户习题-已答题过比如上一题 或者下一题（可能不存在）
     *
     * @param h5QaPracticeErrorQuery
     * @return
     */
    Page<ActivityQuestionInfo> findUserQaLog(H5QaPracticeErrorQuery h5QaPracticeErrorQuery);


    /**
     * H5新版本答题提交
     *
     * @param qaCommitCommand
     * @return
     */
    UserQaScoreResponse doH5PlusQaCommit(QaCommitCommand qaCommitCommand);

    UserQaInfo findByUserIdAndQaInfoIdAndActivityId(String userId, String qaInfoId, String activityId);

    List<ActivityQuestionInfo> queryQaInfoId(String qaInfoId, List<String> userSubmitQuestionIdList);


    Query getQaQuery(String userId, String qaInfoId, String activityId);


    Optional<CertificateActivityConfig> getCertificateActivityConfig(Integer type, ActivityQaInfo activityQaInfo, ActivityInfo activityInfo);

    /**
     * 退款成功，用户答题清除
     *
     * @param userId
     * @param activityId
     */
    void removePassedRefundQa(String userId, String activityId);

    /**
     * 用户答题题库等分记录
     *
     * @param req
     * @return
     */
    Page<UserQaInfo> list(UserQaQueryVO req);


    UserQaInfo findOne(String id);

    /**
     * 批量导入用户答题记录
     * @param inputStream
     * @param fileName
     * @param activityId
     * @param qaInfoId
     * @return
     */
    Map<String, Object> batchImportQaRecord(byte[] inputStream, String fileName, String activityId, String qaInfoId);

    /**
     * 根据用户id 与活动id 删除用户答题记录
     * @param userId
     * @param activityId
     */
    void deleteByUserIdAndActivityId(String userId, String activityId);
}
